﻿using System;
using System.Collections.Generic;
using System.Text;
using OpenTK;

using OpenTK.Input;
using OpenTK.Graphics.OpenGL;
using Xeno.Core;
using Xeno.Module;
using System.Drawing;
using OpenTK;
namespace Xeno.GUI
{

    public class XuiGroup : XuiWidget
    {
        public string Text { get; set; }
        public XenoText.XenoTextCache TextCache { get; set; }
        public XuiGroup(Vector2 size,string text)
            : base(size)
        {
            Text = text;
            TextCache = XenoText.CreateText(text);
        }
      

        public override void DoRender()
        {

            Vector3 wp = Attached.WorldPosition;
            if (CullNodes)
            {
                GL.Enable(EnableCap.ScissorTest);
                GL.Scissor((int)wp.X, (int)XenoCore.DisplayHeight - (int)wp.Y - (int)Size.Y, (int)Size.X, (int)Size.Y);
            }
            //ScrollY -= XenoApp.Instance.Mouse.WheelDelta * 10;
            //if (ScrollY < 0) ScrollY = 0;

           // RenderNode(Graph.RootNode, wp.X + 10, wp.Y + 10 - ScrollY);
           // GL.Disable(EnableCap.ScissorTest);
            Begin2D();


            GL.Color4(Color.WhiteSmoke);
            
            GL.Begin(BeginMode.Quads);

            GL.Vertex2(wp.X, wp.Y);
            GL.Vertex2(wp.X + Size.X, wp.Y);

            GL.Color4(Color.DarkGray);

            GL.Vertex2(wp.X + Size.X, wp.Y + Size.Y);
            GL.Vertex2(wp.X, wp.Y + Size.Y);


            GL.End();

            GL.LineWidth(2);
            GL.Begin(BeginMode.Lines);

            GL.Color4(Color.DarkSlateGray);

            GL.Vertex2(wp.X, wp.Y);
            GL.Vertex2(wp.X, wp.Y + Size.Y);
            GL.Vertex2(wp.X, wp.Y);
            GL.Vertex2(wp.X + Size.X, wp.Y);

            GL.Vertex2(wp.X + Size.X, wp.Y);
            GL.Vertex2(wp.X + Size.X, wp.Y + Size.Y);

            GL.Vertex2(wp.X, wp.Y + Size.Y);

            GL.Vertex2(wp.X + Size.X, wp.Y + Size.Y);

            GL.End();

            float tx = wp.X + Size.X / 2 - (TextCache.Width / 2);
            float ty = wp.Y+5;
            End2D();

            XenoText.DrawText(TextCache, (int)tx, (int)ty,Color.Black);
        }

    }

}
